/**
 * 
 * Copyright (C) 2011 Cody Stoutenburg . All rights reserved.
 *
 *       This program is free software; you can redistribute it and/or
 *       modify it under the terms of the GNU Lesser General Public License
 *       as published by the Free Software Foundation; either version 2.1
 *       of the License, or (at your option) any later version.
 *
 *       This program is distributed in the hope that it will be useful,
 *       but WITHOUT ANY WARRANTY; without even the implied warranty of
 *       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *       GNU Lesser General Public License for more details.
 *
 *       You should have received a copy of the GNU Lesser General Public License
 *       along with this program; if not, write to the Free Software
 *       Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. 
 * 
 */
package client;

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

import javax.swing.JTextArea;

import client.gui.PanelContactList;
import client.message.IRemoteString;
import client.shared.Message;
import client.shared.MessageReceiver;

public class DisplayMessage extends UnicastRemoteObject
		implements
			MessageReceiver {

	private static final long serialVersionUID = 4607806122708770922L;

	private final JTextArea textArea;
	private final PanelContactList contactList;
	private final String name;

	public DisplayMessage(String name, JTextArea textArea,
			PanelContactList contactList) throws RemoteException {
		this.contactList = contactList;
		this.textArea = textArea;
		this.name = name;
	}
	@Override
	public void joinMessage(String name) throws RemoteException {
		contactList.updateClient();
		textArea.append(name + " a rejoint le chat\n");
	}

	@Override
	public void sendMessage(String name, Message message)
			throws RemoteException {

		if (message instanceof IRemoteString) {
			IRemoteString remoteString = (IRemoteString) message;
			textArea.append(name + " dit: " + remoteString.getMessage() + "\n");
		}
	}

	@Override
	public void exitMessage(String name) throws RemoteException {
		contactList.updateClient();
		textArea.append(name + " a quitter le chat.\n");
	}

	@Override
	public String getName() throws RemoteException {
		return name;
	}
}